/**
 * 
 */
package ch.comtools.ssh.message;

/**
 * The Message Number is a byte value that describes the payload of a
   packet.
   
 * @author Roger Dudler <roger.dudler@gmail.com>
 * @version $Id$
 */
public abstract class Message {

	public static final int SSH_MSG_DISCONNECT = 1;
	public static final int SSH_MSG_IGNORE = 2;
	public static final int SSH_MSG_UNIMPLEMENTED = 3;
	public static final int SSH_MSG_DEBUG = 4;
	public static final int SSH_MSG_SERVICE_REQUEST = 5;
	public static final int SSH_MSG_SERVICE_ACCEPT = 6;
	public static final int SSH_MSG_KEXINIT = 20;
	public static final int SSH_MSG_NEWKEYS = 21;
	public static final int SSH_MSG_KEXDH_INIT = 30;
	public static final int SSH_MSG_KEXDH_REPLY = 31;
	public static final int SSH_MSG_KEX_DH_GEX_REQUEST_OLD = 30;
	public static final int SSH_MSG_KEX_DH_GEX_REQUEST = 34;
	public static final int SSH_MSG_KEX_DH_GEX_GROUP = 31;
	public static final int SSH_MSG_KEX_DH_GEX_INIT = 32;
	public static final int SSH_MSG_KEX_DH_GEX_REPLY = 33;
	public static final int SSH_MSG_USERAUTH_REQUEST = 50;
	public static final int SSH_MSG_USERAUTH_FAILURE = 51;
	public static final int SSH_MSG_USERAUTH_SUCCESS = 52;
	public static final int SSH_MSG_USERAUTH_BANNER = 53;
	public static final int SSH_MSG_USERAUTH_INFO_REQUEST = 60;
	public static final int SSH_MSG_USERAUTH_INFO_RESPONSE = 61;
	public static final int SSH_MSG_GLOBAL_REQUEST = 80;
	public static final int SSH_MSG_REQUEST_SUCCESS = 81;
	public static final int SSH_MSG_REQUEST_FAILURE = 82;
	public static final int SSH_MSG_CHANNEL_OPEN = 90;
	public static final int SSH_MSG_CHANNEL_OPEN_CONFIRMATION = 91;
	public static final int SSH_MSG_CHANNEL_OPEN_FAILURE = 92;
	public static final int SSH_MSG_CHANNEL_WINDOW_ADJUST = 93;
	public static final int SSH_MSG_CHANNEL_DATA = 94;
	public static final int SSH_MSG_CHANNEL_EXTENDED_DATA = 95;
	public static final int SSH_MSG_CHANNEL_EOF = 96;
	public static final int SSH_MSG_CHANNEL_CLOSE = 97;
	public static final int SSH_MSG_CHANNEL_REQUEST = 98;
	public static final int SSH_MSG_CHANNEL_SUCCESS = 99;
	public static final int SSH_MSG_CHANNEL_FAILURE = 100;
	
	private static final String[] REVERSE = new String[101];

	static {
		REVERSE[1] = "SSH_MSG_DISCONNECT";
		REVERSE[2] = "SSH_MSG_IGNORE";
		REVERSE[3] = "SSH_MSG_UNIMPLEMENTED";
		REVERSE[4] = "SSH_MSG_DEBUG";
		REVERSE[5] = "SSH_MSG_SERVICE_REQUEST";
		REVERSE[6] = "SSH_MSG_SERVICE_ACCEPT";
		REVERSE[20] = "SSH_MSG_KEXINIT";
		REVERSE[21] = "SSH_MSG_NEWKEYS";
		REVERSE[30] = "SSH_MSG_KEXDH_INIT";
		REVERSE[31] = "SSH_MSG_KEXDH_REPLY/SSH_MSG_KEX_DH_GEX_GROUP";
		REVERSE[32] = "SSH_MSG_KEX_DH_GEX_INIT";
		REVERSE[33] = "SSH_MSG_KEX_DH_GEX_REPLY";
		REVERSE[34] = "SSH_MSG_KEX_DH_GEX_REQUEST";
		REVERSE[50] = "SSH_MSG_USERAUTH_REQUEST";
		REVERSE[51] = "SSH_MSG_USERAUTH_FAILURE";
		REVERSE[52] = "SSH_MSG_USERAUTH_SUCCESS";
		REVERSE[53] = "SSH_MSG_USERAUTH_BANNER";
		REVERSE[60] = "SSH_MSG_USERAUTH_INFO_REQUEST";
		REVERSE[61] = "SSH_MSG_USERAUTH_INFO_RESPONSE";
		REVERSE[80] = "SSH_MSG_GLOBAL_REQUEST";
		REVERSE[81] = "SSH_MSG_REQUEST_SUCCESS";
		REVERSE[82] = "SSH_MSG_REQUEST_FAILURE";
		REVERSE[90] = "SSH_MSG_CHANNEL_OPEN";
		REVERSE[91] = "SSH_MSG_CHANNEL_OPEN_CONFIRMATION";
		REVERSE[92] = "SSH_MSG_CHANNEL_OPEN_FAILURE";
		REVERSE[93] = "SSH_MSG_CHANNEL_WINDOW_ADJUST";
		REVERSE[94] = "SSH_MSG_CHANNEL_DATA";
		REVERSE[95] = "SSH_MSG_CHANNEL_EXTENDED_DATA";
		REVERSE[96] = "SSH_MSG_CHANNEL_EOF";
		REVERSE[97] = "SSH_MSG_CHANNEL_CLOSE";
		REVERSE[98] = "SSH_MSG_CHANNEL_REQUEST";
		REVERSE[99] = "SSH_MSG_CHANNEL_SUCCESS";
		REVERSE[100] = "SSH_MSG_CHANNEL_FAILURE";
	}

	/**
	 * Get message type for given message id.
	 * @param type
	 * @return
	 */
	public static final String getMessageName(int type) {
		String res = null;
		if ((type >= 0) && (type < REVERSE.length)) {
			res = REVERSE[type];
		}
		return (res == null) ? ("UNKNOWN MSG " + type) : res;
	}
	
}
